package virtualadvisor;

import java.util.Comparator;

public class SemesterComparator implements Comparator<Semester> {

	/**
	 * Name: compareTo()
	 * Description: 
	 * PreCondition:  none
	 * PostCondition: none
	 */
	@Override
	public int compare(Semester arg0, Semester arg1) {
		int ret = 0;
		if(arg1.getYear() == arg0.getYear()) {
			String ourSeason = arg0.getSeason().toLowerCase();
			String theirSeason = arg1.getSeason().toLowerCase();

			//ret = 0, our semester is their semester.
			//ret = -1, our semester comes before their semester.
			//ret = 1, our semester comes after their semester.
			if(ourSeason.equals("summer") && theirSeason.equals("summer"))     {ret =  0;}
			else if(ourSeason.equals("summer") && theirSeason.equals("fall"))  {ret =  1;}
			else if(ourSeason.equals("summer") && theirSeason.equals("winter")){ret =  1;}
			else if(ourSeason.equals("summer") && theirSeason.equals("spring")){ret =  1;}
			else if(ourSeason.equals("fall") && theirSeason.equals("summer"))  {ret = -1;}
			else if(ourSeason.equals("fall") && theirSeason.equals("fall"))    {ret =  0;}
			else if(ourSeason.equals("fall") && theirSeason.equals("winter"))  {ret = -1;}
			else if(ourSeason.equals("fall") && theirSeason.equals("spring"))  {ret = -1;}
			else if(ourSeason.equals("winter") && theirSeason.equals("summer")){ret = -1;}
			else if(ourSeason.equals("winter") && theirSeason.equals("fall"))  {ret =  1;}
			else if(ourSeason.equals("winter") && theirSeason.equals("winter")){ret =  0;}
			else if(ourSeason.equals("winter") && theirSeason.equals("spring")){ret = -1;}
			else if(ourSeason.equals("spring") && theirSeason.equals("summer")){ret = -1;}
			else if(ourSeason.equals("spring") && theirSeason.equals("fall"))  {ret =  1;}
			else if(ourSeason.equals("spring") && theirSeason.equals("winter")){ret =  1;}
			else if(ourSeason.equals("spring") && theirSeason.equals("spring")){ret =  0;}
		}
		else if(arg0.getYear() < arg1.getYear()){ret = -1;}
		else if(arg0.getYear() > arg1.getYear()){ret =  1;}
		return ret;
	}
}
